<template>
  <div ref="sp">
    <!--点击右上角分享提示-->
    <share v-if="shareState" @cancel="shareState = !shareState"></share>
    <!--点击右上角分享提示end-->
    <!--<div v-if="vueRouterHistory" class="goBack" @click="returnHistory"></div>
    <div v-if="vueRouterHistory1" class="goBack" @click="returnHistory1"></div>-->
    <div v-if="$route.query.goCenter" class="goBack" @click="$router.push({name:'center'})"></div>
    <!--<div v-if="$route.query.vueRouterHistory2" class="goBack" @click="$router.push({path:'/center'})"></div>-->
    <div :class="{'isFixed': isFixed}" class="bg_rose_red">
      <div class="search_card_my clearfix" style="position: relative;">
        <!--<ul class="chooseCoupon1" v-if='!chooseType'>
          <li @click="chooseCouponType('choose')" style="font-size: 1rem;">{{txt}}<i v-if='!chooseType' class="icon iconfont icon-down"></i><i v-else class="icon iconfont icon-iconfontunfold"></i></li>
        </ul>
        <ul class="chooseCouponUp" v-if='chooseType'>
          <li @click="chooseCouponType('xianjin')">现金<i v-if='!chooseType' class="icon iconfont icon-down"></i><i v-else class="icon iconfont icon-iconfontunfold"></i></li>
          <li @click="chooseCouponType('yunquan')">芸券</li>
        </ul>-->
        <i class="iconfont icon-sousuo- left" @click="searchCoupoon"></i>
        <form action="#" @submit.prevent="searchCoupoon">
          <input class="left" v-model="couponSearch" type="text" @focus="cardFocus" @blur="cardBlur"
                 :placeholder="fontContent"/>
        </form>
        <!--即将过期，待使用等按钮-->
        <ul v-if="changeTabUpType" class="chooseCoupon2">
          <li v-for="(item,index) in chooseCoupon2Arr" @click="chooseCoupon2Type(index,item)">{{item}}<span>√</span>
          </li>
        </ul>
        <div class="shadow" @click="closeShadow" v-if="changeTabUpType"></div>
      </div>
      <div class="bg_rose_red" :class="{'switchTit':flagType=='coupon','switchTit1':flagType=='cash'}">
        <p :class="{hot: indexTab=='0'||indexTab=='4'||indexTab=='5'}" @click="changeTabUp()">
          {{TxT}}({{chooseValue}}) <i class="icon iconfont icon-down"></i></p>
        <p :class="{hot: indexTab=='1'}" @click="changeTab('1')">全部商券({{all}})<i class="icon iconfont icon-down"></i>
        </p>
        <p :class="{hot: indexTab=='2'}" @click="changeTab('2')">价值最高({{worth}})<i class="icon iconfont icon-down"></i>
        </p>
        <p v-if="flagType=='coupon'" :class="{hot: indexTab=='3'}" @click="changeTab('3')">已挂单({{selling}})<i
            class="icon iconfont icon-down"></i></p>
      </div>

    </div>
    <div class="cardList" v-infinite-scroll="moreList" infinite-scroll-disabled="loading"
         infinite-scroll-immediate-check="true" infinite-scroll-distance="100">
      <ul>
        <li v-for="(item,index) in myCoupon" :key='index' :class="indexTab!=1&&indexTab!=4&&item.delayed==4?'dbn':''">
          <div :class="item.num<=1?'cardBg1 bgc_tp':'cardBg1'">
            <div class="bgLine">
              <img v-if="item.num<=1" src="../../images/cardBg_05.png">
              <img v-if="item.num>1" src="../../images/cardBg.png">
            </div>
            <!--<img v-if="item.type=='rebate'&&item.couponTypes!='third'" style="position: absolute;height: 6rem;z-index: 4;right: -.5rem;top: 3rem;" src="../../images/cardListUse.png">-->
            <img v-if="item.promAppro=='buy'"
                 style="position: absolute;width: 1rem;height:1rem;z-index: 4;left: 1rem;top: 0.5rem;"
                 src="../../images/cashIcon.png"/>
            <img v-if="item.couponTypes=='third'&&item.promAppro=='buy'"
                 style="position: absolute;width: 1rem;height:1rem;z-index: 4;left: 2.2rem;top: 0.5rem;"
                 src="../../images/dui.png"/>
            <img v-if="item.couponTypes=='third'&&item.promAppro!='buy'"
                 style="position: absolute;width: 1rem;height:1rem;z-index: 4;left: 1rem;top: 0.5rem;"
                 src="../../images/dui.png"/>
            <img v-if="item.couStat=='used'&&item.couponTypes=='third'"
                 style="position: absolute;width: 5rem;height: 5rem;right: 1rem;z-index: 4;top: 2rem"
                 src="../../images/used_03.png"/>
            <div class="cardBg2" @click="goCouponDetl(item)">
              <div v-if="item.delayed!=4" class="card_tit clearfix">
                <span class="right">有效期：{{item.validatyEnd | strDate(3)}}</span>
                <p :class="{'goright':item.promAppro=='buy'||item.couponTypes=='third','goright1':item.promAppro=='buy'&&item.couponTypes=='third'}">
                  {{item.mchtName}}</p>
              </div>
              <div v-if="item.delayed==4" class="card_tit card_overdue clearfix">
                <span class="right">该电子券已过期</span>
                <p :class="{'goright':item.promAppro=='buy'||item.couponTypes=='third','goright1':item.promAppro=='buy'&&item.couponTypes=='third'}">
                  {{item.mchtName}}</p>
              </div>
              <div class="couponDiv">
                <coupon-denomination :item="item"></coupon-denomination>
              </div>
              <div class="card_info">
                <div class="card_name more">
                  {{item.name}}
                  <a class="icon_share_cardList" @click.stop="clickIconShare(item)"
                     v-if="item.delayed!=4 && !(item.type2 == 'useonly' || (item.couStat == 'used' && item.couponTypes == 'third' || item.couStat == 'listing'&&item.type2=='default' ))">
                    <icon iconName="#icon-fenxiang"></icon>
                    分享&nbsp;&nbsp;
                  </a>
                </div>
                <div class="coupon_info_item">
                  <p class="star_con">
                    <star :couponComScore="item.comScore"></star>
                  </p>
                  <p class="info_pad">{{item.comNum}}条 {{item.type | couponTp}}共{{item.num}}张</p>
                </div>

                <div class="coupon_info_item color_gray">
                  已出售 {{item.soldnum}} 已使用 {{item.usednum}}
                </div>
              </div>
            </div>
            <div v-if="item.delayed!=4"
                 :class="{'card_btn_two_add':state=='state','card_btn_three':item.type=='ticket'||item.type=='present'||(item.couStat=='used'&&item.couponTypes=='third'),'card_btn_four':(item.type=='cash'||item.type=='rebate'||item.type=='voucher')&&item.couStat!='used'&&!state}">
              <a v-if="state!='state'" @click="shareFriends(item)"
                 :class="{'card_btn_overdue_a':item.couStat == 'listing'||item.type2=='useonly'||(item.couStat == 'used'&&item.couponTypes=='third')}">分享券友</a>
              <a  @click="scan(item)"
                 :class="{'card_btn_overdue_a':item.couStat == 'listing'||item.type2=='useonly'||(item.couStat == 'used'&&item.couponTypes=='third')}">扫描给券</a>
              <a @click="changeMy(item)" v-if="item.couStat == 'normal'&&item.type!=='present'&&item.type!=='ticket'&&state!='state'"
                 :class="{'card_btn_overdue_a':item.couStat == 'listing'||item.type2=='useonly'||item.type2=='share'||state=='state'}">兑换芸券</a>
              <a @click="recallOrder(item)" v-if="item.couStat == 'listing'&&item.type2=='default'&&state!='state' ">撤回芸券</a>
              <a @click="use(item)" :class="{'card_btn_overdue_a':item.couStat == 'listing'}">使用此券</a>
            </div>

            <div v-if="item.delayed==4" class="card_btn_overdue"
                 :class="{'card_btn_two_add':state=='state','card_btn_one_add':item.type2=='useonly','card_btn_three':item.type2=='share','card_btn_four':item.type!=='present'&&item.type!=='ticket'&&(item.type2=='default'||item.type2=='share')&&!state}">
              <a>分享券友</a>
              <a v-if="state!='state'">扫描给券</a>
              <a v-if="item.type!=='present'&&item.type!=='ticket'&&state!='state'">兑换芸券</a>
              <a>使用此券</a>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <!-- 分享成功弹框 -->
    <share-success @clickBack="hiddenShareInfo(2)" v-if="successShare" :noReward="noReward"></share-success>
    <!-- 奖励提醒弹框 -->
    <remind-modal v-if="shareInfo" :type="shareType" @close="shareInfo = false"
                  @click_btn="reward_modal_btn"></remind-modal>
    <!-- 奖励显示弹框 -->
    <reward-modal v-if="shareInfo1" @close="hiddenShareInfo(2)" :money="usrAmt" :state="status"></reward-modal>
    <!-- 出售弹框 -->
    <sell v-if="sellBox" :param="faParam" v-on:btnOk="sellBoxEvent" class="sell_component"></sell>
    <recall :boxShow2="recallBox" :param="faParam" v-on:btnOk2="recallBoxEvent" class="recall_component"></recall>
    <go-top v-show="goTopState" ref="goTopId" class="goTop_component"></go-top>
    <no-data v-if="noInfo" color='white'></no-data>
    <div class="lastInfoMore" v-if="!moreInfo && !noInfo &&myCoupon.length>3">没有更多</div>
    <modal v-if="thirdDescArrState">
    	<div class="model">
    		<div class="modalTxt">使用须知</div>
    		<div>
    			<ul class="modalUl">
    				<li v-for="item in thirdDescString.thirdDescArr">{{item}}</li>
    			</ul>
    		</div>
    		<div class="modalBtn" @click="modalBtn">确定</div>
    	</div>
    </modal>
  </div>
</template>
<script>
  import sell from '../../componentes/global/sell.vue'
  import recall from '../../componentes/global/recall.vue'
  import star from '../../componentes/global/star.vue'
  import listLoading from '../../componentes/global/listLoading.vue'
  import RewardModal from 'src/componentes/global/reward/index.vue'
  import RemindModal from 'src/componentes/global/reward/remind.vue'
  import * as types from '../../vuex/types.js'
  import {
    Storage
  } from 'src/utils/storage.js'
  import ShareSuccess from '../coupon/shareList/success.vue'
  import share from '../../componentes/global/share.vue'
  import {
    mapState
  } from 'vuex'
  import getData from '../../service/getData.js'
  import {
    Toast,
    Indicator,
    MessageBox
  } from 'mint-ui';
  import {
    shareMyCoupon
  } from '../../service/getData3';
  import {
    Common
  } from 'src/utils/common.js'
  import getData4 from '../../service/getData4.js'

  export default {
    name: "cardList",
    data() {
      return {
        sellBox: false, //控制出售box
        recallBox: false, //控制撤回box
        indexTab: '1',
        noMoreCoupon: true,
        loading: true,
        faParam: {},
        couponSearch: '',
        fontContent: "搜索电子券名称或相关店铺",
        moreInfo: true, // 是否有更多信息
        noInfo: false, // list是否为空
        isFixed: false,
        card_btn: 'card_btn',
        card_btn_new: 'card_btn_new',
        resultt: [],
        Codetypes: '',
        denomination: '',
        goTopState: false,
        expire: '', // 即将过期
        all: '', // 全部商券
        worth: '', // 价值最高
        selling: '', // 已挂单
        wait: '',//待使用
        delayed: '',//已过期
        chooseValue: '',
        vueRouterHistory: '',
        vueRouterHistory1: '',
        shareInfo: false, //有奖励金的提示框
        shareType: '', //点击按钮的类型：分享、扫码、使用
        scanCouponId: '',
        scanMchtId: '',
        useCouponId: '',
        useMchtId: '',
        status: true, //分享中的提示语显示是否为核销后得到奖励金
        info: {},
        shareInfo1: false,
        usrAmt: 0,
        flag: 0,
        padding: false,
        successShare: false,
        noReward: false,
        currentItem: {}, // 当有奖励金时  存储当前元素
        chooseType: false, //选择现金还是芸券
        txt: '芸券',
        chooseCoupon2Arr: ['即将过期', '待使用', '已过期'],
        changeTabUpType: false,
        flagType: 'coupon',
        TxT: '即将过期',
        shareState: false, // 分享遮罩开关
        state: '',//公众号页面点击商券优惠券只有分享和使用按钮
        thirdDescString:{},//描述分段
        thirdDescArrState:false
        
      }
    },
    watch: {
      shareState(v) {
        if (!v) {
          Common.wechatShare() // 恢复全局的邀请链接
        }
      }
    },
    mounted: function () {
    },
    beforeRouteLeave(to, from, next) {
      // 避免返回时未清除定时器
      if (this.$refs.goTopId) {
        this.$refs.goTopId.clear();
      }
      if(window.isBack&&this.$route.query.vueRouterHistory){
  		window.isBack = false
  		this.$router.push({path:"/home"})
  	}
      window.removeEventListener('scroll', this.gotopScroll);
      if (this.$route.query.jump == '1' || to.path === '/paySuccess') {
  		next()
      } else {
        next()
      }
    },
    destroyed() {
      document.body.style.background = '';
    },
    components: {
      sell,
      listLoading,
      recall,
      star,
      ShareSuccess,
      RewardModal,
      RemindModal,
      share
    },
    created: function () {
      this.shareType = ''
      this.vueRouterHistory = this.$route.query.vueRouterHistory;//根据传参判断返回页面
      this.vueRouterHistory1 = this.$route.query.vueRouterHistory1;//根据传参判断返回页面
      this.state = this.$route.query.channel == 0 ? 'state' : '';
      // 监视滚动
      window.addEventListener('scroll', this.handleScroll);
      window.addEventListener('scroll', this.gotopScroll);
      document.body.style.background = 'rgb(246, 87, 127)';
      let me = this;
      if (this.$route.query.infoType) {
        me.indexTab = this.$route.query.infoType;
        me.flagType = 'coupon'
        me.txt = '芸券'
      }
      this.$store.commit(types.CHANGE_COUPON_PAGE, 1);
      this.$store.commit(types.GET_MY_COUPONS);
      this.$store.commit(types.GET_SCORLL_STATUS, true);
      this.clickMoreList();
      //解决ios返回出现空白问题
      this.cardTotal({
        usrId: me.userInfo.usrId
      })
      setTimeout(function () {
        window.scrollTo(0, 1)
        window.scrollTo(0, 0)
      }, 100)

    },
    computed: {
      ...mapState({
        myCoupon: state => state.center.myCoupon,
        windowH: state => state.com.windowH,
        couponsPageLimit: state => state.center.couponsPageLimit,
        userInfo: state => state.user.userInfo,
      }),
    },
    methods: {
      // 分享优惠券给微信好友按钮
      async clickIconShare(data) {
        /*请求该券券码*/
        let result = await getData4.findShareCouponNo({
          method: 'post',
          data: {
            couponId: data.couponId,
            mchtId: data.mchtId,
            usrId: this.userInfo.usrId
          }
        });
        let cpCodeList = [];
        if (result.respCode === "00") {
          cpCodeList = JSON.parse(result.content).couponNos.split(',')
        } else {
          Toast({
            message: result.errorInfo,
            duration: 800
          });
          setTimeout(function () {
            location.reload();
          }, 800)
          return
        }

        this.shareState = true;
        Common.setWechatShare({
          title: "文字不是重点，好友分享不可辜负哦！", // 分享标题
          desc: "你的好友" + `${this.userInfo.usrName}` + "分享了一张优惠券给你，速速收下吧", // 分享描述
          link: '/getFriendCoupon?mchtId=' + data.mchtId + '&usrId=' + this.userInfo.usrId + '&couponId=' + data.couponId + '&cpCode=' + cpCodeList[0], // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: process.env.DOMAIN_NAME + "/shareCouponForFriend.jpg"
        })
      },
      cardTotal: function (data) {
        var me = this
        getData.countCouponNum({
          method: 'post',
          data: data
        }).then(function (rep) {
          me.all = rep.content.all
          me.worth = rep.content.worth
          me.selling = rep.content.selling
          me.chooseValue = me.expire = rep.content.expire
          me.wait = rep.content.wait
          me.delayed = rep.content.delayed


        })
      },
      gotopScroll() {
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        var scrollHeight = document.documentElement.clientHeight || document.body.scrollTop;
        if (scrollTop >= scrollHeight + 50) {
          this.goTopState = true
        } else {
          this.goTopState = false
        }
        //回到顶部过程中用户滚动滚动条，停止定时器
        if (scrollTop <= 0) {
          if (this.$refs.goTopId) {
            this.$refs.goTopId.clear();
          }
        }
      },
      //监听滚动事件
      handleScroll() {
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        if (scrollTop > 0) {
          this.changeTabUpType = false
        }
        if (scrollTop >= 50) {
          this.isFixed = true
        } else if (scrollTop <= 0) {
          this.isFixed = false
        }
      },
      cardFocus: function () {
        this.fontContent = ""
      },
      cardBlur: function () {
        this.fontContent = "搜索电子券名称或相关店铺"
      },
      goCouponDetl(params) {
        let me = this
        if (params.delayed == '4') {
          Toast({
            message: '该电子券已过期',
            duration: 1000
          });
        } else {

//      if ((params.promAppro == 'buy') && params.type != 'ticket' && params.type != 'present'&&params.couponTypes!='third') {
//
//        Storage.set("couponInfo", params);
//        me.$router.push({
//          name: 'cashCouDetail',
//          query: {
//            type: 'noExchange',
//            couponId: params.couponId,
//            mchtId: params.mchtId,
//            seq: params.seqNo || '',
//            usrId: params.usrId || '',
//            usrPicId: '',
//            num: params.num
//          }
//        });
//
//
//
//      } else {
//        Storage.set("couponInfo", params);
//        me.$router.push({
//          name: 'couDetail',
//          query: {
//            type: 'noExchange',
//            couponId: params.couponId,
//            mchtId: params.mchtId,
//            seq: params.seqNo || '',
//            usrId: params.usrId || '',
//            usrPicId: '',
//            num: params.num,
//            share:true
//          }
//        });
//
//      }
          if (params.couStat == 'used' && params.couponTypes == 'third') {
            me.$router.push({
              "path": '/expiredDetail/' + params.mchtId + '/' + params.couponId + '/' + params.num,
              query: {used: true, couStat: params.couStat, type2: params.couStat}
            });
          } else {
            me.$router.push({
              "path": '/expiredDetail/' + params.mchtId + '/' + params.couponId + '/' + params.num,
              query: {couStat: params.couStat, type2: params.type2}
            });
          }
        }
      },
      /**
       * 头部选项卡
       */
      changeTab: function (num) {
        if (num == 1 || num == 2 || num == 3) {
          this.changeTabUpType = false
        }
        this.indexTab = num;
        this.$store.commit(types.CHANGE_COUPON_PAGE, 1);
        this.$store.commit(types.GET_MY_COUPONS);
        this.noInfo = false;
        this.noMoreCoupon = true;
        this.moreInfo = true;
        this.clickMoreList();
      },
      //出售按钮
      /**
       * 出售按钮操作(控制sell框、向子组件传值)(计算出售给小云价格)
       * */
      changeMy: async function (item) {
        /*请求该券券码*/
        let result = await getData4.findShareCouponNo({
          method: 'post',
          data: {
            couponId: item.couponId,
            mchtId: item.mchtId,
            usrId: this.userInfo.usrId
          }
        });
        if (result.respCode === "00") {
          if (item.type2 == 'useonly' || item.type2 == 'share' || this.state == 'state') {
            Toast({
              message: '该电子券暂不能兑换',
              duration: 1000
            });
            return
          }

          let me = this;

          if (item) {
            //                    me.faParam = item;
            getData.computePrice({
              method: 'post',
              mchtId: item.mchtId,
              couponId: item.couponId
            }).then(rep => {
              item.price = rep.content.valuation;
              me.faParam = item;
            })
            me.sellBoxEvent("hidden");
          } else {
            me.sellBoxEvent("hidden");
          }
        } else {
          Toast({
            message: result.errorInfo,
            duration: 800
          });
          setTimeout(function () {
            location.reload();
          }, 800)
        }

      },
      sellBoxEvent: function (hidden) {
        this.sellBox = this.sellBox ? false : true;
        let str = navigator.userAgent.toLowerCase();
        let ver = str.match(/cpu iphone os (.*?) like mac os/);
        if (!ver) {
        } else {
        }
        if (hidden == 'hidden') {
          return;
        }
        this.refresh();
      },
      // 撤回按钮
      recallOrder: function (item, index) {
        // Indicator.open('验证中...');
        this.$store.commit('changeState', true)
        let me = this;
        getData.validateCancel({
          method: 'post',
          data: {
            seqNo: item.seqNo,
            usrId: me.userInfo.usrId
          }
        }).then(function (rep) {
          if (rep.respCode == '00') {
            item.index = index;
            me.faParam = item;
            me.recallBoxEvent("hidden");
          } else {
            Toast({
              message: '此电子券已经被购买,请刷新后重试!',
              duration: 1000
            });
            setTimeout(function () {
              location.reload();
            }, 800)
          }
        }).catch(function (rep) {
          // Indicator.close();
          me.$store.commit('changeState', false)
        })

      },
      recallBoxEvent: function (hidden) {
        this.recallBox = this.recallBox ? false : true;
        //document.body.style.overflow = this.recallBox ? 'hidden' : 'auto';
        if (hidden == 'hidden') {
          return;
        }
        this.refresh();
      },
      /**
       * 点击加载框 加载数据
       * */
      clickMoreList: function () {

        if (!this.noMoreCoupon) { //防止重复点击
          return
        }
        let me = this;
        this.noMoreCoupon = false;
        this.$store.dispatch('getMyCoupons', {
          method: 'post',
          data: {
            "type": me.indexTab,
            "couponName": me.couponSearch,
          }
        }).then(function (rep) {
          me.resultt = rep.content.couponList
          if (rep.respCode != '00') {
            Toast({
              message: rep.errorInfo,
              duration: 1000
            });
          }
          if (rep.content.total <= 0) {
            if (me.flag == 0) { //第一次请求
              me.noInfo = true;
            } else { //不是第一请求
              me.noInfo = false;
            }
          } else {
            me.noInfo = false;
          }
          if (rep.content.couponList) {
            if (rep.content.couponList.length < me.couponsPageLimit && !(rep.content.couponList.length == 0)) {
              // console.log(111)
              setTimeout(function () {
                me.noMoreCoupon = true;
              }, 300);
              me.noInfo = false;
              me.moreInfo = false;
            }
            if (rep.content.couponList.length == me.couponsPageLimit) { //如果列表数据够10条，开启下拉加载
              me.moreInfo = false;
              me.loading = false;
              me.noMoreCoupon = true;
              me.flag = 1;

            }
            if (rep.content.couponList.length == 0) {
              setTimeout(function () {
                me.noMoreCoupon = true;
              }, 300);
              me.noInfo = false;
              me.moreInfo = false;
            }
            //判断存在已过期券影响无数据提示显示隐藏
            if (me.indexTab != 1 && me.indexTab != 4) {
              // console.log(rep.content.couponList.length)
              var delayArry = [];
              for (var i = 0; i < rep.content.couponList.length; i++) {

                if (rep.content.couponList[i].delayed == 4) {
                  delayArry.push(rep.content.couponList[i])
                }
              }
              if (delayArry.length == me.myCoupon.length) {
                me.noInfo = true;
                me.moreInfo = true;
              } else {
                me.noInfo = false;
                me.moreInfo = false;
                // console.log(333)
              }
            }

          } else {

            setTimeout(function () {
              me.noMoreCoupon = true;
            }, 300);
          }
        }).catch(function (rep) {
          setTimeout(function () {
            me.noMoreCoupon = true;
          }, 300);
        });
      },
      moreList: function () {
        this.loading = true;
        this.noMoreCoupon = true;
        this.clickMoreList();
      },
      refresh: function () {
        this.$store.commit(types.CHANGE_COUPON_PAGE, 1);
        this.$store.commit(types.GET_MY_COUPONS);
        this.clickMoreList();
        this.cardTotal({
          usrId: this.userInfo.usrId
        });
        this.shareType = ''
      },
      // 搜索电子券名称
      searchCoupoon: function () {
        console.log(this.couponSearch);
        this.$store.commit(types.CHANGE_COUPON_PAGE, 1);
        this.$store.commit(types.GET_MY_COUPONS);
        this.clickMoreList();
      },
      // 奖励提醒
      rewardRemind(type, coupon) {
        this.shareInfo = true; //打开分享奖励提示
        // if (type === 'button' || type === 'scan'|| type === 'onlyTwo'|| type === 'scanOnlyTwo') { // 分享 扫描
        //   this.shareType = type;
        // } else if (type === 'use') {
        //   this.shareType = 'use';
        // }
        this.shareType = type
        this.currentItem = coupon
      },
      //分享券友按钮
      shareFriends: async function (coupon, nextStep = false) {
        /*请求该券券码*/
       if(coupon.couStat == 'listing'&&coupon.type2=='default'){
       	Toast({
                  message: '该电子券暂不能分享',
                  duration: 1000
                });
                return
       }
         if (coupon.type2 == 'useonly' || (coupon.couStat == 'used' && coupon.couponTypes == 'third')) {
            Toast({
              message: "该电子券暂不能分享",
              duration: 1000
            });
            return
          }
        let result = await getData4.findShareCouponNo({
          method: 'post',
          data: {
            couponId: coupon.couponId,
            mchtId: coupon.mchtId,
            usrId: this.userInfo.usrId
          }
        });
        if (result.respCode === "00") {        
          // shareProp    一级分钱的分享比例、扫描比例
          // useProp      使用比例
          // verFlag      奖励金  0:核销后  1:核销前
          // shareLvl     一级分钱的分享层级
          // shareCon     二级分钱的分享奖励
          // settShareLvl 二级分钱的分享层级
          if (!nextStep && coupon.shareProp && coupon.shareLvl) { //判断此券分享操作是否有奖励
            this.rewardRemind('button', coupon)
          } else if (!nextStep && coupon.shareCon && coupon.settShareLvl) { // 二级分享奖励判断
            this.rewardRemind('onlyTwo', coupon)
          } else {
            this.$store.commit('shareCoup', {
              couponId: coupon.couponId,
              mchtId: coupon.mchtId,
              num: coupon.num
            });
            this.$router.push({
              name: 'friendShare',
              params: {
                type: '0',
              }
            });
          }
        } else {
          Toast({
            message: result.errorInfo,
            duration: 800
          });
          setTimeout(function () {
            location.reload();
          }, 800)
        }
      },
      //扫描给券按钮
      scan: async function (coupon, nextStep) {
      	if(coupon.couStat == 'listing'&&coupon.type2=='default'){
       	Toast({
                  message: '该电子券暂不能扫描',
                  duration: 1000
                });
                return
       }
        /*请求该券券码*/
        let result = await getData4.findShareCouponNo({
          method: 'post',
          data: {
            couponId: coupon.couponId,
            mchtId: coupon.mchtId,
            usrId: this.userInfo.usrId
          }
        });
        if (result.respCode == "00") {
          if (coupon.type2 == 'useonly' || (coupon.couStat == 'used' && coupon.couponTypes == 'third')) {
            Toast({
              message: "该电子券暂不能扫描",
              duration: 1000
            });
            return
          }

          this.scanCouponId = coupon.couponId;
          this.scanMchtId = coupon.mchtId;
          if (!nextStep && coupon.shareProp && coupon.shareLvl) { //判断此券扫码分享操作是否有奖励机制
            this.rewardRemind('scan', coupon)
          } else if (!nextStep && coupon.shareCon && coupon.settShareLvl) {
            this.rewardRemind('scanOnlyTwo', coupon)
          } else {
            new Promise((resolve, reject) => {
              wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                success: function (res) {
                  var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                  resolve(result);
                }
              });
            }).then(rep => {
              let obj = JSON.parse(rep.substr(rep.indexOf("V=") + 2, rep.length - 1));
              if (obj.usrId) {
                if (obj.usrId == this.userInfo.usrId) {
                  Toast({
                    message: '不能分享给自己',
                    duration: 800
                  });
                  return;
                }
                //扫码分享券给用户调用接口
                let me = this;
                shareMyCoupon({
                  usrId: me.userInfo.usrId, //分享人
                  couponId: me.scanCouponId,
                  mchtId: me.scanMchtId,
                  num: 1,
                  shareId: [obj.usrId], //获得者
                  shareType: "scan"
                }).then(function (rep) {
                  if (rep.respCode == '00') {
                  	me.cardTotal({
							          usrId: me.userInfo.usrId
							        });
                    if (rep.content.ifHasShareAmt) {
                      me.status = rep.content.verFlag === '0' ? true : false //核销后给奖励，添加提示语（待入账）
                      me.shareInfo1 = true
                      me.usrAmt = rep.content.usrAmt;
                    } else {
                      if (coupon.shareLvl == null) {
                        me.noReward = false // nextStep false: 无奖励金提醒  true: 有奖励金提醒
                      } else {
                        me.noReward = nextStep // nextStep false: 无奖励金提醒  true: 有奖励金提醒
                      }

                      me.successShare = true //分享成功
                    }
                  } else {
                    Toast({
                      message: rep.errorInfo,
                      duration: 1000
                    });
                  }
                }).catch(() => {
                  Toast({
                    message: "操作失败",
                    duration: 1000
                  });
                })
              } else {
                Toast({
                  message: "二维码不正确",
                  duration: 1000
                });
              }
            }).catch(function (error) {
              Toast({
                message: error || "操作失败",
                duration: 1000
              });
            });
          }
        } else {
          Toast({
            message: result.errorInfo,
            duration: 800
          });
          setTimeout(function () {
            location.reload();
          }, 800)
        }
      },
      //使用按钮
      use: async function (params, nextStep) {     	
        var me = this
        /*请求该券券码*/
       if(params.couStat == 'listing'&&params.type2=='default'){
       	Toast({
                  message: '该电子券暂不能使用',
                  duration: 1000
                });
                return
       }
        let result = await getData4.findShareCouponNo({
          method: 'post',
          data: {
            couponId: params.couponId,
            mchtId: params.mchtId,
            usrId: this.userInfo.usrId
          }
        });
        if (params.couStat == 'used' && params.couponTypes == 'third') {
          me.$router.push({
            'name': 'usedRedeemCode',
            query: {couponId: params.couponId, mchtId: params.mchtId}
          });
          return
        }
        if (result.respCode === "00") {
          //console.log(params.type)
          this.info = {
            resultt: this.resultt,
            Codetypes: params.type,
            name: params.name,
            mchtName: params.mchtName,
            soldnum: params.soldnum,
            usednum: params.usednum,
            mchtId: params.mchtId,
            denomination: params.denomination,
            couponId: params.couponId,
            num: params.num,
            validatyBegin: params.validatyBegin,
            validatyEnd: params.validatyEnd
          };
          Storage.set("info", me.info, true);
          this.useCouponId = params.couponId;
          this.useMchtId = params.mchtId;
          if (!nextStep && params.verFlag && params.useProp && !(params.useProp == 0)) { //判断此券是否有奖励机制
            this.rewardRemind('use', params)
          } else {
            getData.findCode({
              method: 'post',
              data: {
                couponId: this.useCouponId,
                mchtId: this.useMchtId,
                usrId: me.userInfo.usrId
              }
            }).then(function (rep) {
              if (rep.respCode == '01') {
                Toast({
                  message: rep.errorInfo,
                  duration: 1000
                });
              } else {
                if (params.couponTypes == 'third') {
                  let couNo = JSON.parse(rep.content).couponNos.split(',')[0]
                  getData.findThirdDesc({
                    method: 'post',
                    data: {mchtId: params.mchtId, couponId: params.couponId}
                  }).then(function (res) {
                    let message = res.content.content.thirdDesc
                    
                    	 if (message != '') {
                    	 	//第三方券有链接
                    	 	if(res.content.content.thirdType=='url'){
                    	 		 me.$router.push({
		                        'name': 'RedeemCode',
		                        query: {couNo: couNo, mchtId: params.mchtId, couponId: params.couponId,thirdUrlState:'true',thirdUrlDesc:message}
		                      });
                    	 	}else{
                    	 		me.thirdDescArrState=true
                    	me.thirdDescString.thirdDescArr=message.split('；')
                    	me.thirdDescString.couponMxt={couNo: couNo, mchtId: params.mchtId, couponId: params.couponId}
                    	 	}
                    	
                    } else {
                      me.$router.push({
                        'name': 'RedeemCode',
                        query: {couNo: couNo, mchtId: params.mchtId, couponId: params.couponId}
                      });
                    }
                    
                   

                  })

                } else {
                  me.$router.push({
                    'name': 'useYunConpons',
                    query: {
//            	guoqi:true,
                      mchtId: params.mchtId,
                      couponId: params.couponId,
                      couponName: params.name
                    }

                  });
                }
              }
            })
          }
        } else {
          Toast({
            message: result.errorInfo,
            duration: 800
          });
          setTimeout(function () {
            location.reload();
          }, 800)
        }      
      },
      // 有奖励机制的优惠券操作：分享、扫码、使用
      reward_modal_btn(type) {
        if (type === 'button' || type === 'onlyTwo') { // 分享
          this.shareFriends(this.currentItem, true)
        } else if (type === 'scan' || type === 'scanOnlyTwo') {
          this.scan(this.currentItem, true)
        } else if (type === 'use') {
          this.use(this.currentItem, true)
        }
      },
      //关闭分享奖励提示
      hiddenShareInfo(type) {
        this.shareInfo = false;
        this.shareInfo1 = false;
        this.shareType = '';
        if (type == 2) {
          this.successShare = false
          this.$store.commit(types.CHANGE_COUPON_PAGE, 1);
          this.$store.commit(types.GET_MY_COUPONS);
          this.$store.commit(types.GET_SCORLL_STATUS, true);
          this.clickMoreList();
        }
      },
//    returnHistory() {
//      window.history.go(-3)
//    },
//    returnHistory1() {
//      window.history.go(-2)
//    },
//  chooseCouponType(item){
//  	let me=this
//  	me.changeTabUpType=false
//  	if(item=='choose'){
//  		me.chooseType=me.chooseType?false:true
//  	}else if(item=='xianjin'){
//  		me.txt='现金'
//  		me.chooseType=false
//  		me.flagType='cash'
//  	me.$store.commit(types.CHANGE_COUPON_PAGE, 1);
//    me.$store.commit(types.GET_MY_COUPONS);
//    me.noInfo = false;
//    me.noMoreCoupon = true;
//    me.moreInfo = true;
//    me.clickMoreList();
//  	}else if(item=='yunquan'){
//  		me.txt='芸券'
//  		me.chooseType=false
//  		me.flagType='coupon'
//  	me.$store.commit(types.CHANGE_COUPON_PAGE, 1);
//    me.$store.commit(types.GET_MY_COUPONS);
//    me.noInfo = false;
//    me.noMoreCoupon = true;
//    me.moreInfo = true;
//    me.clickMoreList();
//  	}
//  	 me.cardTotal({
//  	 flag:me.flagType,
//      type:me.indexTab,
//      usrId:me.userInfo.usrId
//    });
//  },
      changeTabUp() {
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        this.changeTabUpType = this.changeTabUpType ? false : true
      },
      chooseCoupon2Type(item, i) {
        let me = this
        me.TxT = i
        document.getElementsByClassName('chooseCoupon2')[0].getElementsByTagName('li')[item].style.color = 'red'
        document.getElementsByClassName('chooseCoupon2')[0].getElementsByTagName('li')[item].getElementsByTagName('span')[0].style.display = 'block'
        if (item == 0) {
          me.indexTab = 0
          me.chooseValue = me.expire
        } else if (item == 1) {
          me.indexTab = 5
          me.chooseValue = me.wait
        } else if (item == 2) {
          me.indexTab = 4
          me.chooseValue = me.delayed
        }
        me.$store.commit(types.CHANGE_COUPON_PAGE, 1);
        me.$store.commit(types.GET_MY_COUPONS);
        me.noInfo = false;
        me.noMoreCoupon = true;
        me.moreInfo = true;
        me.clickMoreList();
        setTimeout(function () {
          me.changeTabUpType = false
        }, 200);

      },
      closeShadow() {
        this.changeTabUpType = false
      },
      modalBtn(){
      	let me=this
      	me.$router.push({
             'name': 'RedeemCode',
              query: me.thirdDescString.couponMxt
        });
      }

    }
  }
</script>
<style scoped>
  .icon_share_cardList {
    color: #999999
  }

  i {
    font-size: 1rem;
  }

  .isFixed {
    position: fixed;
    top: 0;
    z-index: 10;
    width: 100%;
  }

  .card_overdue {
    color: #ff0000;
  }

  .card_btn_overdue a {
    color: #999;
  }

  .card_btn_overdue_a {
    color: #999;
  }

  .share_a {
    color: #999;
  }

  .dbn {
    display: none;
  }

  .goright {
    margin-left: 1.4rem;
  }

  .goright1 {
    margin-left: 2.4rem;
  }

  .search_card_my {
    width: 100%;
    color: #fde7ea;
    background-color: #fa6f8e;
    padding: 0.75rem 0;
    /*  margin-left: 26%;*/
  }

  .search_card_my input {
    background-color: #fa6f8e;
    color: #fff;
    height: 17px;
    font-size: 1rem;
    width: 85%;
    text-indent: 1rem;
  }

  .search_card_my input::-webkit-input-placeholder {
    color: #fde7ea;
  }

  .search_card_my .iconfont {
    margin: 0 0.65rem 0 0.85rem;
  }

  .lastInfoMore {
    color: #fff;
  }

  /*新增*/

  .sell_con {
    overflow-y: auto;
    box-sizing: border-box;
    z-index: 11 !important;
  }

  .switchTit p {
    float: left;
    width: 25%;
    text-align: center;
    position: relative;
    border: none;
  }

  .switchTit p,
  .switchTit p i.icon {
    font-size: .85rem
  }

  .switchTit .hot {
    color: #fff
  }

  .recall_component {
    z-index: 99;
  }

  .sell_component {
    z-index: 99;
  }

  .goTop_component {
    z-index: 98;
  }

  .shadowBox {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .8);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 88 !important;
  }

  .goBack {
    z-index: 30;
    position: absolute;
    left: 0;
    top: 0;
    width: 50px;
    height: 50px;
  }

  .chooseCoupon1 {
    position: absolute;
    left: -33%;
    top: 0rem;
    background-color: #fa6f8e;
    width: 5.5rem;
    text-align: center;
    z-index: 1;
  }

  .chooseCoupon1 li {
    width: 5.5rem;
    height: 2.8rem;
    line-height: 2.8rem;
  }

  .chooseCouponUp {
    position: absolute;
    left: -33%;
    top: 0rem;
    background-color: #fa6f8e;
    width: 5.5rem;
    text-align: center;
    z-index: 1;
  }

  .chooseCouponUp li:nth-of-type(1) {
    width: 5.5rem;
    height: 2.8rem;
    line-height: 2.8rem;
  }

  .chooseCouponUp li:nth-of-type(2) {
    width: 5.5rem;
    height: 2.8rem;
    line-height: 2.8rem;
    text-indent: -2.3rem;
  }

  .chooseCoupon2 {
    position: absolute;
    left: -7rem;
    top: 5rem;
    z-index: 60;
    width: 138%;
  }

  .chooseCoupon2 li {
    width: 100%;
    height: 3rem;
    line-height: 3rem;
    background: #fff;
    border-bottom: 1px solid gainsboro;
    text-indent: 8rem;
    font-size: .85rem;
    color: #3F3F3F;
  }

  .chooseCoupon2 li span {
    color: #f6577f;
    float: right;
    margin-right: 6rem;
    display: none;
  }

  .shadow {
    width: 138%;
    height: 50rem;
    background: #222222;
    opacity: .7;
    z-index: 67;
    position: absolute;
    left: -7rem;
    top: 14rem;
  }
  .model{ 	
	min-height: 10rem;
	width: 90%;
	background: #ffffff;
	border-radius: 1rem;
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
  }
  .modalTxt{	
  	height: 2rem;
  	line-height: 2rem;
  	text-align: center;
  	width: 100%;
  }
  .modalUl{
  	width: 100%;
  	padding:1rem 2rem;
  	min-height: 6rem;
  	word-break:break-all;
  }
  .modalBtn{
  	background: #ee5088;
  	color:#FFFFFF ;
  	text-align: center;
  	line-height: 2.5rem;
  	height: 2.5rem;
  	width: 100%;
  	border-bottom-left-radius: 1rem;
  	border-bottom-right-radius: 1rem;
  }
  .more{
  	width: 15rem;
  	white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
</style>